package com.chap15;

import com.lmax.disruptor.RingBuffer;

/**
 * <p>
 * <code>OrderEventProducer</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-04-18 14:50
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class OrderEventProducer {
    private RingBuffer<OrderEvent> ringBuffer;

    public OrderEventProducer(RingBuffer<OrderEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(long value,String name){
        long sequence = ringBuffer.next();

        try{
            OrderEvent orderEvent = ringBuffer.get(sequence);
            orderEvent.setValue(value);
            orderEvent.setName(name);
        }catch (Exception e){

        }finally {
            System.out.println("生产者发送数据：value："+value+",name:"+name);
            ringBuffer.publish(sequence);
        }
    }
}
